<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  function arr(n) {
    let str = '1';
    while (--n > 0) {
      let count = 1,
        tempStr = '';
      for (let i = 0; i < str.length; i++) {
        // 如果相邻的字符相同，则count+1，
        if (str[i] == str[i + 1]) count++;
        else {
          tempStr += (count + str[i]);
          count = 1;
        }
      }
      str = tempStr;
    }
    // 返回结果
    return str;
  }
  console.log(arr(n = 1));
</script>

</html>